package com.bci.pwtz.service.impl;

import com.bci.pwtz.mysql.dao.LoginDeviceCodeMapper;
import com.bci.pwtz.mysql.model.LoginDeviceCode;
import com.bci.pwtz.service.LoginDeviceCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by admin on 2017/10/18.
 */
@Service
public class LoginDeviceCodeServiceImpl implements LoginDeviceCodeService {

    LoginDeviceCodeMapper loginDeviceMapper;

    public void setLoginDeviceMapper(LoginDeviceCodeMapper loginDeviceMapper) {
        this.loginDeviceMapper = loginDeviceMapper;
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return loginDeviceMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(LoginDeviceCode record) {
        return loginDeviceMapper.insert(record);
    }

    @Override
    public int insertSelective(LoginDeviceCode record) {
        return loginDeviceMapper.insertSelective(record);
    }

    @Override
    public LoginDeviceCode selectByPrimaryKey(Integer id) {
        return loginDeviceMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(LoginDeviceCode record) {
        return loginDeviceMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(LoginDeviceCode record) {
        return loginDeviceMapper.updateByPrimaryKey(record);
    }

    @Override
    public LoginDeviceCode findInfo(String phone) {
        return loginDeviceMapper.findInfo(phone);
    }

    @Override
    public boolean isThisDevice(String devicecode, String phone) {
        LoginDeviceCode loginDeviceCode=findInfo(phone);
        if(loginDeviceCode==null){//还未在数据库中绑定设备
            loginDeviceCode=new LoginDeviceCode();
            loginDeviceCode.setDevicecode(devicecode);
            loginDeviceCode.setPhone(phone);
            loginDeviceCode.setId(0);
            insert(loginDeviceCode);
            return true;
        }else if(loginDeviceCode!=null && !loginDeviceCode.getDevicecode().equals(devicecode)) {//该设备不正确
            return false;
        }else{
            return true;
        }
    }
}
